<template>
  <d2-container>
    <template slot="header">职业规划点评（共计：{{ totalcount }}条）</template>
    <div class="careerplancomments-table">
      <el-table :data="careerComments" border size="mini" style="width: 100%">
        <el-table-column
          prop="careerplan_id.title"
          label="职业规划标题"
          width="220"
        ></el-table-column>
        <el-table-column
          prop="user_id.username"
          label="职业规划作者"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="experts_id.experts_name"
          label="评论专家"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="content"
          label="评论内容"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="create_time"
          label="创建时间"
          width="150"
        ></el-table-column>
        <el-table-column label="操作" fixed="right" width="56">
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            circle
            :disabled="disabled"
            @click="under"
          ></el-button
        ></el-table-column>
      </el-table>
      <!-- 分页部分 -->
      <div class="pagination" v-if="totalcount > 10">
        <el-pagination
          background
          layout="prev, pager, next"
          :page-size="pagesize"
          @current-change="pageChange"
          :current-page.sync="currentPage"
          :total="this.totalcount"
        ></el-pagination>
      </div>
    </div>
  </d2-container>
</template>

<script>
import { getCareerCommentList } from '@/api/api'
import util from '@/libs/util.js'
import { dbGet } from '@/libs/util.db'
export default {
  name: 'careercomment',
  data () {
    return {
      pagenow: 1,
      pagesize: 10,
      currentPage: 1,
      totalcount: 0,
      careerComments: [],
      disabled: true,
      userid: '',
      roleid: '',
      userinfo: {},
      expertinfo: {}
    }
  },
  created () {
    this.expertinfo = dbGet({
      dbName: 'expertinfo',
      path: 'expertinfo'
    })
    this.userinfo = dbGet({
      dbName: 'userinfo',
      path: 'userinfo'
    })
    this.roleid = dbGet({
      dbName: 'roleid',
      path: 'roleid'
    })
    this.userid = util.cookies.get('user_id')
    this.getList()
  },
  methods: {
    getList () {
      const params = {
        user_id: this.roleid >= 3 ? '' : this.userid,
        pagenow: this.pagenow,
        experts_id: ''
      }
      if (this.roleid === 3) {
        params.experts_id = this.expertinfo.experts_id
      }
      getCareerCommentList(params).then(res => {
        if (res.code === 401) {
          this.$toast(res.message, 'error')
        }
        this.careerComments = res.data.data
        this.totalcount = res.data.totalcount
      })
    },
    pageChange (currentPage) {
      this.pagenow = currentPage
      this.currentPage = currentPage
      this.getList()
    },
    under () {}
  }
}
</script>

<style lang="scss">
.careerplancomments-table {
  text-align: center;
  width: 100%;
  .pagination {
    margin: 20px;
    text-align: center;
  }
  .el-pagination {
    justify-content: center;
  }
}
</style>
